package com.pactera.integral.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.pactera.integral.common.repository.ResultMap;
import com.pactera.integral.common.web.GenericController;
import com.pactera.integral.common.web.Response;
import com.pactera.integral.entity.UserPerformanceScore;
import com.pactera.integral.service.PerformanceScoreService;

@CrossOrigin
@RestController
@RequestMapping("wx/performance")
public class UserPerformanceScoreController extends GenericController {

	@Autowired
	private PerformanceScoreService performanceScoreService;

	@RequestMapping("/show")
	public Response getListForShow() {
		return this.normal(performanceScoreService.getListForShow());
	}

	@RequestMapping("/detail")
	public Response getDetailForShow(@RequestParam String staffId, @RequestParam String year,
			@RequestParam String month) {
		return this.normal(performanceScoreService.getDetailForShow(staffId, year, month));
	}

	@RequestMapping(value = "/save/{staffId}", method = RequestMethod.POST)
	public Response addScore(@PathVariable("staffId") String staffId,
			@RequestBody List<UserPerformanceScore> userPerformanceScore) {
		return this.normal(performanceScoreService.addScore(staffId, userPerformanceScore));
	}

	@RequestMapping(value = "/check", method = RequestMethod.GET)
	public Response checkScore(@RequestParam String staffId, @RequestParam String month, @RequestParam String year) {
		return this.normal(performanceScoreService.checkUserPerformanceScore(staffId, month, year));
	}

	@RequestMapping(value = "/history", method = RequestMethod.GET)
	public Response getPerformanceScoreHistory(@RequestParam String staffId) {
		return this.normal(performanceScoreService.getScoreHistory(staffId));
	}

	@RequestMapping(value = "/user", method = RequestMethod.GET)
	public Response getUserId(@RequestParam String staffId, @RequestParam String year,
	                          @RequestParam String month,@RequestParam(required = false) String userName) {
		List<ResultMap<String, Object>> list = performanceScoreService.getUserId(staffId,userName, year, month);

		return this.normal(list);
	}
}
